<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>展开语法</title>
</head>
<body>
    <script>
        // //数组展开
        // names = ["1","cq","3q","po"];
        // console.log(...names);
        // //实现浅拷贝
        // let person = {
        //     name:"cq",
        //     "age":18,
        //     height:1.99
        // }
        
        // let stu = {
        //     ...person,
        //     grade:100,
        //     id:2003123
        // }
        // console.log(stu);

        // //stu里面的obj不是person
        // person.name = "kobe";
        // person.age = 30;

        //数组展开
        names = ["1","cq","3q","po"];
        console.log(...names);


        //实现浅拷贝
        let person = {
            name:"cq",
            "age":18,
            height:1.99,
            //添加对象：这个对象不能被拷贝
            friend:{
               name:"curry",
               age:23,
               height:1.91
            }
        }

        // let stu = {
        //     ...person,//浅拷贝
        //     grade:100,
        //     id:2003123
        // }
        
        //使用json实现深拷贝
        const stu = JSON.parse(JSON.stringify(person));
        stu.grades = 100;
        stu.id = 12345;
        //改变person的friend
        person.friend.name = "james";
        person.friend.age = 40;
        person.friend.height = 2.03;
        //打印
        console.log(stu.friend.name);
        console.log(stu.friend.age);
        console.log(stu.friend.height);

        
    </script>
</body>
</html>